package com.gitee.wsl.struct.grammar.ast.process.marker

import com.gitee.wsl.struct.grammar.ast.node.NodeType
import com.gitee.wsl.struct.grammar.ast.process.sequential.SequentialParser


class ProductionHolder {
    var currentPosition: Int = 0
        private set

    private val _production : MutableList<SequentialParser.Node> = ArrayList()

    val production: List<SequentialParser.Node>
        get() = _production


    fun updatePosition(position: Int) {
        currentPosition = position
    }

    fun addProduction(nodes: Collection<SequentialParser.Node>) {
        _production.addAll(nodes)
    }

    fun mark(): Marker {
        return Marker()
    }

    inner class Marker {
        private val startPos: Int = currentPosition

        fun done(type: NodeType) {
            _production.add(SequentialParser.Node(startPos..currentPosition, type))
        }
    }
}
